package com.focus.xyz.union.pages.frontend.tables;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BaseTable;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Created by chenmeng on 2016/4/20.
 */
public class ApiTable extends BaseTable {
    @FindBy(xpath = "//table[@class='tab-info tab-border']/tbody")
    private WebElement table;

    public ApiTable(WebDriver driver,Action action){
        super(action);
        PageFactory.initElements(driver,this);
        super.table = table;
    }


    @Override
    protected By getLinkLocator() throws Exception {
        return By.xpath("td[6]/a");
    }

    @Override
    protected By getLocator(int index) throws Exception {
        return By.xpath("td[" + index + "]/div");
    }

    public void linkModify(String key) throws Exception{
        selectRowAndClickLink(table,key,"修改");
    }

    public void linkDel(String key) throws Exception{
        selectRowAndClickLink(table,key,"删除");
        action.waitForAlert();
        action.acceptAlert();
    }

    public void linDetail(String key) throws Exception{
        selectRowAndClickLink(table,key,"查看详情");
    }

    public String getStatus(String key) throws Exception{
        return getCellText(table,key,5);
    }
}
